package com.pzhu.dormitory.controller;

import java.util.Arrays;
import java.util.Map;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.pzhu.dormitory.entity.VisitEntity;
import com.pzhu.dormitory.service.VisitService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Rb;
import com.pzhu.dormitory.utils.R;


/**
 * 访客
 *
 * @author 
 * @email 
 * @date 2021-05-03 02:15:41
 */
@Slf4j
@RestController
@Api(value = "VisitController", tags = "访客")
@RequestMapping("dormitory/visit")
public class VisitController {
    @Autowired
    private VisitService visitService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取访客list")
    public R<VisitEntity> list(@RequestParam Map<String, Object> params) {
        PageUtils<VisitEntity> page = visitService.queryPage(params);
        return Rb.a(VisitEntity.class).success().page(page).build();
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取一个访客信息")
    public R<VisitEntity> info(@Validated @PathVariable("id") Long id) {
            VisitEntity visit = visitService.getById(id);
        return Rb.a(VisitEntity.class).success().withData(visit).build();
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存访客信息")
    @PostMapping("/save")
    public R<VisitEntity> save(@Validated @RequestBody VisitEntity visit) {
            visitService.save(visit);
        return Rb.a(VisitEntity.class).success().build();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新访客信息")
    @PutMapping("/update")
    public R<VisitEntity> update(@RequestBody VisitEntity visit) {
            visitService.updateById(visit);
        return Rb.a(VisitEntity.class).success().build();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除访客信息")
    @DeleteMapping("/delete")
    public R<VisitEntity> delete(@RequestBody Long[] ids) {
            visitService.removeByIds(Arrays.asList(ids));
        return Rb.a(VisitEntity.class).success().build();
    }

}
